package com.alibaba.scala.test1

import org.apache.spark.SparkConf
import org.apache.spark.SparkContext

object SparkTest {
  
  def main(args: Array[String]): Unit = {
  
    val sparkConf = new SparkConf().setMaster("local").setAppName("sparkTest").setMaster("local[1]")
    
    val sc = new SparkContext(sparkConf) 
    
    val map = sc.textFile("/home/admin/sparkdata/test1.txt",1)
      .flatMap(line=>line.split(","))
      .map(w=>(w,1))
      .reduceByKey((v1,v2)=>v1+v2)
      
    map.foreach(e => { println("【" + e._1 + "】出现了" + e._2 + "次") })

    println(map.collect().toBuffer)
    sc.stop()
    
  }
    
    
}